// 由于所有的命名方式保持与C的头文件一致，因此需要使用以下宏来消除编译器警告
#![allow(non_upper_case_globals)]   // 用于抑制编译器关于全局变量命名不规范的警告 正确：全大写下划线分隔 MAX_VALUE
#![allow(non_camel_case_types)]     // 用于抑制编译器关于类型命名不规范的警告 正确：驼峰命名法 MyStruct
#![allow(non_snake_case)]           // 用于抑制编译器关于变量命名不规范的警告 正确：蛇形命名法 my_variable
#![allow(dead_code)]                // 用于抑制编译器关于未使用代码的警告

// 引入 Rust FFI 相关的库
use std::ffi::{c_void, c_char};


// -----------------------------------------------------------


/// # mv3drgbd.rs - 海康机器人RGBD相机SDK Rust绑定
/// 
/// 本模块提供了对海康机器人RGBD相机SDK的Rust语言绑定，包含以下主要组件：
/// 
/// ## 模块组件
/// - **状态码定义**：SDK操作返回值和错误码
/// - **常量定义**：SDK中使用的各类常量
/// - **枚举定义**：设备类型、图像格式等枚举类型
/// - **数据结构定义**：设备信息、图像数据等结构体
/// - **回调接口类型定义**：数据回调和异常回调函数
/// - **函数声明**：SDK功能函数的FFI声明
/// - **自定义初始化方法**：SDK数据结构的自定义初始化方法
/// 
/// ## 使用说明
/// 使用此模块前需要先调用`MV3D_RGBD_Initialize()`初始化SDK环境，
/// 使用完成后调用`MV3D_RGBD_Release()`释放资源。


// -----------------------------------------------------------


/// # 状态码定义
/// 未定义
pub const MV3D_RGBD_UNDEFINED: isize =          0xFFFFFFFF;   // 不要定义成 -1，图像数据会出错
/// 正确码定义
pub const MV3D_RGBD_OK: u32 =                   0x00000000;

/// ## 通用错误码定义:范围 0x80060000-0x800600FF 
/// 错误或无效的句柄
pub const MV3D_RGBD_E_HANDLE: u32 =             0x80060000;
/// 不支持的功能
pub const MV3D_RGBD_E_SUPPORT: u32 =            0x80060001;
/// 缓存已满
pub const MV3D_RGBD_E_BUFOVER: u32 =            0x80060002;
/// 函数调用顺序错误
pub const MV3D_RGBD_E_CALLORDER: u32 =          0x80060003;
/// 错误的参数
pub const MV3D_RGBD_E_PARAMETER: u32 =          0x80060004;
/// 资源申请失败
pub const MV3D_RGBD_E_RESOURCE: u32 =           0x80060005;
/// 无数据
pub const MV3D_RGBD_E_NODATA: u32 =             0x80060006;
/// 前置条件有误，或运行环境已发生变化
pub const MV3D_RGBD_E_PRECONDITION: u32 =       0x80060007;
/// 版本不匹配
pub const MV3D_RGBD_E_VERSION: u32 =            0x80060008;
/// 传入的内存空间不足
pub const MV3D_RGBD_E_NOENOUGH_BUF: u32 =       0x80060009;
/// 异常图像，可能是丢包导致图像不完整
pub const MV3D_RGBD_E_ABNORMAL_IMAGE: u32 =     0x8006000A;
/// 动态导入DLL失败
pub const MV3D_RGBD_E_LOAD_LIBRARY: u32 =       0x8006000B;
/// 算法错误
pub const MV3D_RGBD_E_ALGORITHM: u32 =          0x8006000C;
/// 设备离线
pub const MV3D_RGBD_E_DEVICE_OFFLINE: u32 =     0x8006000D;
/// 设备无访问权限
pub const MV3D_RGBD_E_ACCESS_DENIED: u32 =      0x8006000E;
/// 值超出范围
pub const MV3D_RGBD_E_OUTOFRANGE: u32 =         0x8006000F;
/// 升级固件不匹配
pub const MV3D_RGBD_E_UPG_FILE_MISMATCH: u32 =  0x80060010;
/// 升级冲突
pub const MV3D_RGBD_E_UPG_CONFLICT: u32 =       0x80060012;
/// 升级时相机内部出现错误
pub const MV3D_RGBD_E_UPG_INNER_ERR: u32 =      0x80060013;
/// 行业属性不匹配
pub const MV3D_RGBD_E_INDUSTRY: u32 =           0x80060020;
/// 网络相关错误
pub const MV3D_RGBD_E_NETWORK: u32 =            0x80060021;
/// 未知的错误
pub const MV3D_RGBD_E_UNKNOW: u32 =             0x800600FF;


// -----------------------------------------------------------


/// # 常量定义
/// ## 常量
/// 最大图片个数
pub const MV3D_RGBD_MAX_IMAGE_COUNT: u32 =      10;
/// 最大字符串长度
pub const MV3D_RGBD_MAX_STRING_LENGTH: u32 =    256;
/// 最大路径长度
pub const MV3D_RGBD_MAX_PATH_LENGTH: u32 =      256;
/// 最大枚举数量
pub const MV3D_RGBD_MAX_ENUM_COUNT: u32 =       16;

/// ## 像素类型
/// Mono像素格式
pub const MV3D_RGBD_PIXEL_MONO: isize =         0x01000000;
/// Color像素格式
pub const MV3D_RGBD_PIXEL_COLOR: isize =        0x02000000;
/// 自定义像素格式
pub const MV3D_RGBD_PIXEL_CUSTOM: isize =       0x80000000; 
/// [宏]像素格式
#[macro_export]
macro_rules! MV3D_RGBD_PIXEL_BIT_COUNT {
    ($n:expr) => {($n << 16)};
}

/// ## 属性常量定义
/// 图像宽
pub const MV3D_RGBD_INT_WIDTH: &str =           "Width";
/// 图像高
pub const MV3D_RGBD_INT_HEIGHT: &str =          "Height";
/// 工作模式
pub const MV3D_RGBD_ENUM_WORKINGMODE: &str =    "CameraWorkingMode";
/// 像素格式
pub const MV3D_RGBD_ENUM_PIXELFORMAT: &str =    "PixelFormat";
/// 图像模式
pub const MV3D_RGBD_ENUM_IMAGEMODE: &str =      "ImageMode";
/// 增益
pub const MV3D_RGBD_FLOAT_GAIN: &str =          "Gain";
/// 曝光时间
pub const MV3D_RGBD_FLOAT_EXPOSURETIME: &str =  "ExposureTime";
/// 采集帧率
pub const MV3D_RGBD_FLOAT_FRAMERATE: &str =     "AcquisitionFrameRate";
/// 触发选择器
pub const MV3D_RGBD_ENUM_TRIGGERSELECTOR: &str ="TriggerSelector";
/// 触发模式
pub const MV3D_RGBD_ENUM_TRIGGERMODE: &str =    "TriggerMode";
/// 触发源
pub const MV3D_RGBD_ENUM_TRIGGERSOURCE: &str =  "TriggerSource";
/// 触发延迟时间
pub const MV3D_RGBD_FLOAT_TRIGGERDELAY: &str =  "TriggerDelay";
/// 深度图对齐到RGB坐标系（默认值1：对齐；0：不对齐），重启程序后恢复默认值
pub const MV3D_RGBD_INT_IMAGEALIGN: &str =      "ImageAlign";
/// 投射器使能
pub const MV3D_RGBD_BOOL_LASERENABLE: &str =    "LaserEnable";
/// 左右目基线距
pub const Mv3D_RGBD_FLOAT_BASEDISTANCE: &str =  "BaseDistance";
/// 采集分辨率
pub const MV3D_RGBD_ENUM_RESOLUTION: &str =     "BinningSelector";
/// RGBD图像输出（默认值0：不输出；1：输出），重启程序后恢复默认值
pub const MV3D_RGBD_INT_OUTPUT_RGBD: &str =     "OutputRgbd";
/// 设备控制超时时间
pub const MV3D_RGBD_INT_DEVICE_TIMEOUT: &str =  "DeviceTimeout";
/// 图像缓存节点个数
pub const MV3D_RGBD_INT_IMAGE_NODE_NUM: &str =  "ImageNodeNum";
/// 深度图量纲(mm)
pub const MV3D_RGBD_FLOAT_Z_UNIT: &str =        "ZUnit";

/// ## 属性常量定义
/// 相机传感器标定文件
pub const MV3D_RGBD_SENSOR_CALI: &str =         "RGBDSensorCali";
/// 相机手眼标定文件
pub const MV3D_RGBD_HANDEYE_CALI: &str =        "RGBDHandEyeCali";

/// ## 类型定义
/// 返回值类型
pub type MV3D_RGBD_STATUS =                     u32;
/// 句柄类型
pub type HANDLE =                               *mut c_void;
/// BOOL类型
pub type BOOL =                                 u32;


// -----------------------------------------------------------


/// # 枚举定义
#[repr(C)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd)]
/// 设备类型
pub enum Mv3dRgbdDeviceType {
    /// 网口设备
    DeviceType_Ethernet                     = 1 << 0,
    /// USB设备
    DeviceType_USB                          = 1 << 1,
    /// 虚拟网口设备
    DeviceType_Ethernet_Vir                 = 1 << 2,
    /// 虚拟USB设备
    DeviceType_USB_Vir                      = 1 << 3
}

#[repr(C)]
#[derive(Debug, Clone, Copy)]
/// IP类型
pub enum Mv3dRgbdIpCfgMode {
    /// 静态IP
    IpCfgMode_Static                        = 1,
    /// 自动分配IP(DHCP)
    IpCfgMode_DHCP                          = 2,
    /// 自动分配IP(LLA)
    IpCfgMode_LLA                           = 4
}

#[repr(C)]
#[derive(Debug, Clone, Copy)]
/// USB协议类型
pub enum Mv3dRgbdUsbProtocol {
    UsbProtocol_USB2                        = 1,
    UsbProtocol_USB3                        = 2
}

#[repr(C)]
#[derive(Debug, Clone, Copy, PartialEq)]
/// 图像格式
pub enum Mv3dRgbdImageType {
    ImageType_Undefined                     = MV3D_RGBD_UNDEFINED,
    ImageType_Mono8                         = (MV3D_RGBD_PIXEL_MONO  | MV3D_RGBD_PIXEL_BIT_COUNT!(8)  | 0x0001),     //0x01080001,(Mono8)
    ImageType_Mono16                        = (MV3D_RGBD_PIXEL_MONO  | MV3D_RGBD_PIXEL_BIT_COUNT!(16) | 0x0007),     //0x01100007,(Mono16)
    ImageType_Depth                         = (MV3D_RGBD_PIXEL_MONO  | MV3D_RGBD_PIXEL_BIT_COUNT!(16) | 0x00B8),     //0x011000B8,(C16)
    ImageType_YUV422                        = (MV3D_RGBD_PIXEL_COLOR | MV3D_RGBD_PIXEL_BIT_COUNT!(16) | 0x0032),     //0x02100032
    ImageType_YUV420SP_NV12                 = (MV3D_RGBD_PIXEL_COLOR | MV3D_RGBD_PIXEL_BIT_COUNT!(12) | 0x8001),     //0x020C8001
    ImageType_YUV420SP_NV21                 = (MV3D_RGBD_PIXEL_COLOR | MV3D_RGBD_PIXEL_BIT_COUNT!(12) | 0x8002),     //0x020C8002
    ImageType_RGB8_Planar                   = (MV3D_RGBD_PIXEL_COLOR | MV3D_RGBD_PIXEL_BIT_COUNT!(24) | 0x0021),     //0x02180021
    ImageType_PointCloud                    = (MV3D_RGBD_PIXEL_COLOR | MV3D_RGBD_PIXEL_BIT_COUNT!(96) | 0x00C0),     //0x026000C0,(ABC32f)
    ImageType_Jpeg                          = (MV3D_RGBD_PIXEL_CUSTOM| MV3D_RGBD_PIXEL_BIT_COUNT!(24) | 0x0001),     //0x80180001,
    ImageType_Rgbd                          = (MV3D_RGBD_PIXEL_CUSTOM| MV3D_RGBD_PIXEL_COLOR| MV3D_RGBD_PIXEL_BIT_COUNT!(40) | 0x3007),    //0x82283007
}

#[repr(C)]
#[derive(Debug, Clone, Copy)]
/// 数据流类型
pub enum Mv3dRgbdStreamType {
    /// 未定义的数据流类型
    StreamType_Undefined                    = 0,
    /// 深度图数据流
    StreamType_Depth                        = 1,
    /// 彩色图数据流
    StreamType_Color                        = 2,
    /// 矫正后的左目图数据流
    StreamType_Ir_Left                      = 3,
    /// 矫正后的右目图数据流
    StreamType_Ir_Right                     = 4,
    /// IMU数据流
    StreamType_Imu                          = 5,
    /// 左目泛光图数据流
    StreamType_LeftMono                     = 6,
    /// 掩膜图数据流
    StreamType_Mask                         = 7,
    /// 未矫正的左右目融合图数据流
    StreamType_Mono                         = 8,
    /// 相位图数据流
    StreamType_Phase                        = 9,
    /// RGB-D图数据流 
    StreamType_Rgbd                         = 10
}

#[repr(C)]
#[derive(Debug, Clone, Copy)]
/// 坐标系类型
pub enum Mv3dRgbdCoordinateType {
    /// 未定义的坐标系
    CoordinateType_Undefined                = 0,
    /// 深度图坐标系
    CoordinateType_Depth                    = 1,
    /// RGB图坐标系
    CoordinateType_RGB                      = 2
}

#[repr(C)]
#[derive(Debug, Clone, Copy)]
/// 异常信息
pub enum Mv3dRgbdDevException {
    /// 设备断开连接
    DevException_Disconnect                 = 1
}

#[repr(C)]
#[derive(Debug, Clone, Copy)]
/// 参数类型
pub enum Mv3dRgbdParamType {
    ParamType_Bool                          = 1,
    ParamType_Int                           = 2,
    ParamType_Float                         = 3,
    ParamType_Enum                          = 4,
    ParamType_String                        = 5
}

#[repr(C)]
#[derive(Debug, Clone, Copy)]
/// 深度图与rgb图存图格式
pub enum Mv3dRgbdFileType {
    FileType_BMP                            = 1,
    FileType_JPG                            = 2,
    FileType_TIFF                           = 3
}

#[repr(C)]
#[derive(Debug, Clone, Copy)]
/// 点云图存图格式
pub enum Mv3dRgbdPointCloudFileType {
    PointCloudFileType_PLY                  = 1,
    PointCloudFileType_CSV                  = 2,
    PointCloudFileType_OBJ                  = 3,
    PointCloudFileType_PLY_Binary           = 4
}


// -----------------------------------------------------------


/// # 数据结构定义
#[repr(C)]
#[derive(Debug, Clone, Copy)]
pub struct MV3D_RGBD_VERSION_INFO {
    pub nMajor: u32,
    pub nMinor: u32,
    pub nRevision: u32
}

#[repr(C)]
#[derive(Debug, Clone, Copy)]
pub struct MV3D_RGBD_DEVICE_NET_INFO {
    pub chMacAddress: [u8; 8],
    pub enIPCfgMode: Mv3dRgbdIpCfgMode,
    pub chCurrentIp: [c_char; 16],
    pub chCurrentSubNetMask: [c_char; 16],
    pub chDefultGateWay: [c_char; 16],
    pub chNetExport: [c_char; 16],
    pub nReserved: [u8; 16]
}

#[repr(C)]
#[derive(Debug, Clone, Copy)]
pub struct MV3D_RGBD_DEVICE_USB_INFO {
    pub nVendorId: u32,
    pub nProductId: u32,
    pub enUsbProtocol: Mv3dRgbdUsbProtocol,
    pub chDeviceGUID: [c_char; 64],
    pub nReserved: [u8; 16]
}

#[repr(C)]
#[derive(Clone, Copy)]
pub struct MV3D_RGBD_DEVICE_INFO {
    pub chManufacturerName: [c_char; 32],
    pub chModelName: [c_char; 32],
    pub chDeviceVersion: [c_char; 32],
    pub chManufacturerSpecificInfo: [c_char; 44],
    pub nDevTypeInfo: u32,
    pub chSerialNumber: [c_char; 16],
    pub chUserDefinedName: [c_char; 16],
    pub enDeviceType: Mv3dRgbdDeviceType,
    pub SpecialInfo: MV3D_RGBD_DEVICE_INFO_UNION
}

#[repr(C)]
#[derive(Copy, Clone)]
pub union MV3D_RGBD_DEVICE_INFO_UNION {
    pub stNetInfo: MV3D_RGBD_DEVICE_NET_INFO,
    pub stUsbInfo: MV3D_RGBD_DEVICE_USB_INFO,
}

#[repr(C)]
#[derive(Debug, Clone, Copy)]
pub struct MV3D_RGBD_IP_CONFIG {
    pub enIPCfgMode: Mv3dRgbdIpCfgMode,
    pub chDestIp: [c_char; 16],
    pub chDestNetMask: [c_char; 16],
    pub chDestGateWay: [c_char; 16],
    pub nReserved: [u8; 16]
}

#[repr(C)]
#[derive(Debug, Clone, Copy)]
pub struct MV3D_RGBD_IMAGE_DATA {
    pub enImageType: Mv3dRgbdImageType,
    pub nWidth: u32,
    pub nHeight: u32,
    pub pData: *mut u8,
    pub nDataLen: u32,
    pub nFrameNum: u32,
    pub nTimeStamp: i64,
    pub bIsRectified: BOOL,
    pub enStreamType: Mv3dRgbdStreamType,
    pub enCoordinateType: Mv3dRgbdCoordinateType,
    pub nReserved: [u8; 4]
}

#[repr(C)]
#[derive(Debug, Clone, Copy)]
pub struct MV3D_RGBD_FRAME_DATA {
    pub nImageCount: u32,
    pub stImageData: [MV3D_RGBD_IMAGE_DATA; MV3D_RGBD_MAX_IMAGE_COUNT as usize],
    pub nValidInfo: u32,
    pub nReserved: [u8; 12]
}

#[repr(C)]
#[derive(Debug, Clone, Copy)]
pub struct MV3D_RGBD_STREAM_CFG {
    pub enImageType: Mv3dRgbdImageType,
    pub nWidth: u32,
    pub nHeight: u32,
    pub nReserved: [u8; 32]
}

#[repr(C)]
#[derive(Debug, Clone, Copy)]
pub struct MV3D_RGBD_STREAM_CFG_LIST {
    pub nStreamCfgCount: u32,
    pub stStreamCfg: [MV3D_RGBD_STREAM_CFG; MV3D_RGBD_MAX_IMAGE_COUNT as usize],
    pub nReserved: [u8; 16]
}

#[repr(C)]
#[derive(Debug, Clone, Copy)]
pub struct MV3D_RGBD_CAMERA_INTRINSIC {
    pub fData: [f32; 3*3]
}

#[repr(C)]
#[derive(Debug, Clone, Copy)]
pub struct MV3D_RGBD_CAMERA_DISTORTION {
    pub fData: [f32; 12]
}

#[repr(C)]
#[derive(Debug, Clone, Copy)]
pub struct MV3D_RGBD_CALIB_INFO {
    pub stIntrinsic: MV3D_RGBD_CAMERA_INTRINSIC,
    pub stDistortion: MV3D_RGBD_CAMERA_DISTORTION,
    pub nWidth: u32,
    pub nHeight: u32,
    pub nReserved: [u8; 8]
}

#[repr(C)]
#[derive(Debug, Clone, Copy)]
pub struct MV3D_RGBD_CAMERA_EXTRINSIC {
    pub fData: [f32; 4*4]
}

#[repr(C)]
#[derive(Debug, Clone, Copy)]
pub struct MV3D_RGBD_CAMERA_PARAM {
    pub stDepthCalibInfo: MV3D_RGBD_CALIB_INFO,
    pub stRgbCalibInfo: MV3D_RGBD_CALIB_INFO,
    pub stDepth2RgbExtrinsic: MV3D_RGBD_CAMERA_EXTRINSIC,
    pub nReserved: [u8; 32]
}

#[repr(C)]
#[derive(Debug, Clone, Copy)]
pub struct MV3D_RGBD_INTPARAM {
    pub nCurValue: i64,
    pub nMax: i64,
    pub nMin: i64,
    pub nInc: i64
}

#[repr(C)]
#[derive(Debug, Clone, Copy)]
pub struct MV3D_RGBD_ENUMPARAM {
    pub nCurValue: u32,
    pub nSupportedNum: u32,
    pub nSupportValue: [u32; MV3D_RGBD_MAX_ENUM_COUNT as usize]
}

#[repr(C)]
#[derive(Debug, Clone, Copy)]
pub struct MV3D_RGBD_FLOATPARAM {
    pub fCurValue: f32,
    pub fMax: f32,
    pub fMin: f32
}

#[repr(C)]
#[derive(Debug, Clone, Copy)]
pub struct MV3D_RGBD_STRINGPARAM {
    pub chCurValue: [c_char; MV3D_RGBD_MAX_STRING_LENGTH as usize],
    pub nMaxLength: u32
}

#[repr(C)]
#[derive(Clone, Copy)]
pub struct MV3D_RGBD_PARAM {
    pub enParamType: Mv3dRgbdParamType,
    pub ParamInfo: MV3D_RGBD_PARAM_UNION,
    pub nReserved: [u8; 16]
}

#[repr(C)]
#[derive(Copy, Clone)]
pub union MV3D_RGBD_PARAM_UNION {
    pub bBoolParam: BOOL,
    pub stIntParam: MV3D_RGBD_INTPARAM,
    pub stFloatParam: MV3D_RGBD_FLOATPARAM,
    pub stEnumParam: MV3D_RGBD_ENUMPARAM,
    pub stStringParam: MV3D_RGBD_STRINGPARAM,
}

#[repr(C)]
#[derive(Debug, Clone, Copy)]
pub struct MV3D_RGBD_EXCEPTION_INFO {
    pub enExceptionId: Mv3dRgbdDevException,
    pub chExceptionDes: [c_char; MV3D_RGBD_MAX_STRING_LENGTH as usize],
    pub nReserved: [u8; 4]
}

#[repr(C)]
#[derive(Debug, Clone, Copy)]
pub struct MV3D_RGBD_FILE_ACCESS {
    pub pUserFileName: *const c_char,
    pub pDevFileName: *const c_char,
    pub nReserved: [u8; 32]
}

#[repr(C)]
#[derive(Debug, Clone, Copy)]
pub struct MV3D_RGBD_FILE_ACCESS_PROGRESS {
    pub nCompleted: i64,
    pub nTotal: i64,
    pub nReserved: [u8; 32]
}


// -----------------------------------------------------------


/// # 回调接口类型定义
/// 帧数据回调
pub type MV3D_RGBD_FrameDataCallBack = extern "C" fn(pstFrameData: *mut MV3D_RGBD_FRAME_DATA, pUser: *mut c_void);
/// 异常回调
pub type MV3D_RGBD_ExceptionCallBack = extern "C" fn(pstExceptInfo: *mut MV3D_RGBD_EXCEPTION_INFO, pUser: *mut c_void);


// -----------------------------------------------------------

// # 函数声明 不适用///因为 extern "C" 块是外部函数接口声明，rustdoc 不会为它们生成文档
unsafe extern "C" {
    /// 获取SDK版本号
    pub fn MV3D_RGBD_GetSDKVersion(pstVersion: *mut MV3D_RGBD_VERSION_INFO) -> MV3D_RGBD_STATUS;
    /// SDK运行环境初始化
    pub fn MV3D_RGBD_Initialize() -> MV3D_RGBD_STATUS;
    /// SDK运行环境释放
    pub fn MV3D_RGBD_Release() -> MV3D_RGBD_STATUS;

    /// 获取当前环境中设备数量
    pub fn MV3D_RGBD_GetDeviceNumber(nDeviceType: u32, pDeviceNumber: *mut u32) -> MV3D_RGBD_STATUS;
    /// 获取设备列表
    pub fn MV3D_RGBD_GetDeviceList(nDeviceType: u32, pstDeviceInfos: *mut MV3D_RGBD_DEVICE_INFO, 
                                  nMaxDeviceCount: u32, pDeviceCount: *mut u32) -> MV3D_RGBD_STATUS;

                                  
    /// 打开设备
    pub fn MV3D_RGBD_OpenDevice(handle: *mut HANDLE, pstDeviceInfo: *mut MV3D_RGBD_DEVICE_INFO) -> MV3D_RGBD_STATUS;
    /// 通过设备自定义名称打开设备
    pub fn MV3D_RGBD_OpenDeviceByName(handle: *mut HANDLE, chDeviceName: *const c_char) -> MV3D_RGBD_STATUS;
    /// 通过序列号打开设备
    pub fn MV3D_RGBD_OpenDeviceBySerialNumber(handle: *mut HANDLE, chSerialNumber: *const c_char) -> MV3D_RGBD_STATUS;
    /// 通过IP打开设备,仅网口设备有效
    pub fn MV3D_RGBD_OpenDeviceByIp(handle: *mut HANDLE, chIP: *const c_char) -> MV3D_RGBD_STATUS;
    /// 关闭设备
    pub fn MV3D_RGBD_CloseDevice(handle: *mut HANDLE) -> MV3D_RGBD_STATUS;

    /// 获取当前设备的详细信息
    pub fn MV3D_RGBD_GetDeviceInfo(handle: HANDLE, pstDevInfo: *mut MV3D_RGBD_DEVICE_INFO) -> MV3D_RGBD_STATUS;

    /// 配置IP,仅网口设备有效
    pub fn MV3D_RGBD_SetIpConfig(chSerialNumber: *const c_char, pstIPConfig: *mut MV3D_RGBD_IP_CONFIG) -> MV3D_RGBD_STATUS;

    /// 注册图像数据回调
    pub fn MV3D_RGBD_RegisterFrameCallBack(handle: HANDLE, cbOutput: MV3D_RGBD_FrameDataCallBack, 
                                          pUser: *mut c_void) -> MV3D_RGBD_STATUS;
    /// 注册异常消息回调
    pub fn MV3D_RGBD_RegisterExceptionCallBack(handle: HANDLE, cbException: MV3D_RGBD_ExceptionCallBack,
                                              pUser: *mut c_void) -> MV3D_RGBD_STATUS;

    /// 开始取流前获取数据流配置列表
    pub fn MV3D_RGBD_GetStreamCfgList(handle: HANDLE, pstStreamCfgList: *mut MV3D_RGBD_STREAM_CFG_LIST) -> MV3D_RGBD_STATUS;

    /// 开始工作
    pub fn MV3D_RGBD_Start(handle: HANDLE) -> MV3D_RGBD_STATUS;
    /// 停止工作
    pub fn MV3D_RGBD_Stop(handle: HANDLE) -> MV3D_RGBD_STATUS;
    /// 轮询方式获取帧数据
    pub fn MV3D_RGBD_FetchFrame(handle: HANDLE, pstFrameData: *mut MV3D_RGBD_FRAME_DATA, 
                               nTimeOut: u32) -> MV3D_RGBD_STATUS;

    /// 执行设备软触发
    pub fn MV3D_RGBD_SoftTrigger(handle: HANDLE) -> MV3D_RGBD_STATUS;
    /// 执行设备Command命令
    pub fn MV3D_RGBD_Execute(handle: HANDLE, strKey: *const c_char) -> MV3D_RGBD_STATUS;

    /// 获取相机当前标定信息
    pub fn MV3D_RGBD_GetCalibInfo(handle: HANDLE, nCoordinateType: u32, 
                                 pstCalibInfo: *mut MV3D_RGBD_CALIB_INFO) -> MV3D_RGBD_STATUS;
    /// 获取相机内外参信息
    pub fn MV3D_RGBD_GetCameraParam(handle: HANDLE, pstCameraParam: *mut MV3D_RGBD_CAMERA_PARAM) -> MV3D_RGBD_STATUS;

    /// 设备升级
    pub fn MV3D_RGBD_LocalUpgrade(handle: HANDLE, pFilePathName: *const c_char) -> MV3D_RGBD_STATUS;
    /// 获取升级进度
    pub fn MV3D_RGBD_GetUpgradeProcess(handle: HANDLE, pProcess: *mut u32) -> MV3D_RGBD_STATUS;

    /// 获取相机参数值
    pub fn MV3D_RGBD_GetParam(handle: HANDLE, strKey: *const c_char, pstParam: *mut MV3D_RGBD_PARAM) -> MV3D_RGBD_STATUS;
    /// 设置相机参数值
    pub fn MV3D_RGBD_SetParam(handle: HANDLE, strKey: *const c_char, pstParam: *mut MV3D_RGBD_PARAM) -> MV3D_RGBD_STATUS;

    /// 导出相机参数
    pub fn MV3D_RGBD_ExportAllParam(handle: HANDLE, pOutFileName: *const c_char) -> MV3D_RGBD_STATUS;
    /// 导入相机参数
    pub fn MV3D_RGBD_ImportAllParam(handle: HANDLE, pInFileName: *const c_char) -> MV3D_RGBD_STATUS;

    /// 从相机读取文件
    pub fn MV3D_RGBD_FileAccessRead(handle: *mut c_void, pstFileAccess: *mut MV3D_RGBD_FILE_ACCESS) -> MV3D_RGBD_STATUS;
    /// 将文件写入相机
    pub fn MV3D_RGBD_FileAccessWrite(handle: *mut c_void, pstFileAccess: *mut MV3D_RGBD_FILE_ACCESS) -> MV3D_RGBD_STATUS;
    /// 获取文件存取的进度
    pub fn MV3D_RGBD_GetFileAccessProgress(handle: *mut c_void, 
                                         pstFileAccessProgress: *mut MV3D_RGBD_FILE_ACCESS_PROGRESS) -> MV3D_RGBD_STATUS;

    /// RGBD相机深度图像转换点云图像
    pub fn MV3D_RGBD_MapDepthToPointCloud(handle: *mut c_void, pstDepthImage: *mut MV3D_RGBD_IMAGE_DATA,
                                         pstPointCloudImage: *mut MV3D_RGBD_IMAGE_DATA) -> MV3D_RGBD_STATUS;
    /// RGBD相机深度图像转换点云图像（无句柄）
    pub fn MV3D_RGBD_MapDepthToPointCloudEx(pstDepthImage: *mut MV3D_RGBD_IMAGE_DATA, 
                                           pstCalibInfo: *mut MV3D_RGBD_CALIB_INFO,
                                           fZunit: f32, 
                                           pstPointCloudImage: *mut MV3D_RGBD_IMAGE_DATA) -> MV3D_RGBD_STATUS;
    /// 图像坐标系转换
    pub fn MV3D_RGBD_ImageCoordinateTrans(pstInImage: *mut MV3D_RGBD_IMAGE_DATA,
                                         fZunit: f32,
                                         pstOutImage: *mut MV3D_RGBD_IMAGE_DATA,
                                         pstCameraParam: *mut MV3D_RGBD_CAMERA_PARAM) -> MV3D_RGBD_STATUS;
    /// 深度图,RGB图和原始图存图接口
    pub fn MV3D_RGBD_SaveImage(handle: *mut c_void, pstImage: *mut MV3D_RGBD_IMAGE_DATA,
                              enFileType: Mv3dRgbdFileType, chFileName: *const c_char) -> MV3D_RGBD_STATUS;
    /// 点云图存图接口
    pub fn MV3D_RGBD_SavePointCloudImage(handle: *mut c_void, pstImage: *mut MV3D_RGBD_IMAGE_DATA,
                                        enPointCloudFileType: Mv3dRgbdPointCloudFileType,
                                        chFileName: *const c_char) -> MV3D_RGBD_STATUS;
    /// 纹理点云存图接口
    pub fn MV3D_RGBD_SaveTexturedPointCloudImage(handle: *mut c_void, 
                                                pstPointCloudImage: *mut MV3D_RGBD_IMAGE_DATA,
                                                pstTexture: *mut MV3D_RGBD_IMAGE_DATA,
                                                enPointCloudFileType: Mv3dRgbdPointCloudFileType,
                                                chFileName: *const c_char) -> MV3D_RGBD_STATUS;
    /// 显示深度和RGB图像接口
    pub fn MV3D_RGBD_DisplayImage(handle: *mut c_void, pstImage: *mut MV3D_RGBD_IMAGE_DATA,
                                 hWnd: *mut c_void) -> MV3D_RGBD_STATUS;
}


// -----------------------------------------------------------


/// # 自定义初始化方法
impl Default for MV3D_RGBD_VERSION_INFO {
    fn default() -> Self {
        MV3D_RGBD_VERSION_INFO {
            nMajor: 0,
            nMinor: 0,
            nRevision: 0,
        }
    }
}

impl Default for MV3D_RGBD_DEVICE_INFO {
    fn default() -> Self {
        MV3D_RGBD_DEVICE_INFO {
            chManufacturerName: [0; 32],
            chModelName: [0; 32],
            chDeviceVersion: [0; 32],
            chManufacturerSpecificInfo: [0; 44],
            nDevTypeInfo: 0,
            chSerialNumber: [0; 16],
            chUserDefinedName: [0; 16],
            enDeviceType: Mv3dRgbdDeviceType::DeviceType_Ethernet_Vir,
            SpecialInfo: MV3D_RGBD_DEVICE_INFO_UNION {
                stNetInfo: MV3D_RGBD_DEVICE_NET_INFO {
                    chMacAddress: [0; 8],
                    enIPCfgMode: Mv3dRgbdIpCfgMode::IpCfgMode_Static,
                    chCurrentIp: [0; 16],
                    chCurrentSubNetMask: [0; 16],
                    chDefultGateWay: [0; 16],
                    chNetExport: [0; 16],
                    nReserved: [0; 16],
                }
            }
        }
    }
}


impl Default for MV3D_RGBD_FRAME_DATA {
    fn default() -> Self {
        MV3D_RGBD_FRAME_DATA {
            nImageCount: 0,
            stImageData: [MV3D_RGBD_IMAGE_DATA {
                enImageType: Mv3dRgbdImageType::ImageType_Undefined,
                nWidth: 0,
                nHeight: 0,
                pData: std::ptr::null_mut(),
                nDataLen: 0,
                nFrameNum: 0,
                nTimeStamp: 0,
                bIsRectified: BOOL::from(false),
                enStreamType: Mv3dRgbdStreamType::StreamType_Undefined,
                enCoordinateType: Mv3dRgbdCoordinateType::CoordinateType_Undefined,
                nReserved: [0; 4],
            }; MV3D_RGBD_MAX_IMAGE_COUNT as usize],
            nValidInfo: 0,
            nReserved: [0; 12],
        }
    }
}

impl Default for MV3D_RGBD_IMAGE_DATA {
    fn default() -> Self {
        MV3D_RGBD_IMAGE_DATA {
            enImageType: Mv3dRgbdImageType::ImageType_Undefined,
            nWidth: 0,
            nHeight: 0,
            pData: std::ptr::null_mut(),
            nDataLen: 0,
            nFrameNum: 0,
            nTimeStamp: 0,
            bIsRectified: BOOL::from(false),
            enStreamType: Mv3dRgbdStreamType::StreamType_Undefined,
            enCoordinateType: Mv3dRgbdCoordinateType::CoordinateType_Undefined,
            nReserved: [0; 4],
        }
    }
}
